package com.common.library.util;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * Created by Jancy on 16/5/26.
 */
public class DialogUtils extends Dialog implements View.OnClickListener {

    private Context context;
    private TextView tipContentTextView;
    private Button cannelButton,sureButton;
    private LeaveDialogListener listener;
    private String tipContent,cannelText,sureText;

    public interface LeaveDialogListener{
        public void onClick(View view);
    }

    public DialogUtils(Context context,String tipContent,String sureText,String cannelText) {
        super(context);
        // TODO Auto-generated constructor stub
        this.context = context;
        this.tipContent = tipContent;
        this.cannelText = cannelText;
        this.sureText = sureText;
    }

    public DialogUtils(Context context,String tipContent,String sureText,String cannelText,LeaveDialogListener listener) {
        super(context,ActivityHelper.getStyleResId("zs4gamemisc_text_dialog"));
        // TODO Auto-generated constructor stub
        this.context = context;
        this.listener = listener;
        this.tipContent = tipContent;
        this.cannelText = cannelText;
        this.sureText = sureText;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(ActivityHelper.getLayoutResId("zs4gamelayout_view_dialog_show"));

        tipContentTextView       = (TextView)findViewById(ActivityHelper.getIdResId("zs4gameviewid_dialog_text"));
        cannelButton     = (Button)findViewById(ActivityHelper.getIdResId("zs4gameviewid_dialog_btn_cannel"));
        sureButton   = (Button)findViewById(ActivityHelper.getIdResId("zs4gameviewid_dialog_btn_sure"));

        if (Helper.isNotEmpty(tipContent)){
            tipContentTextView.setText(Html.fromHtml(tipContent));
        }if (Helper.isNotEmpty(sureText)){
            sureButton.setText(sureText);
        }if (Helper.isNotEmpty(tipContent)){
            cannelButton.setText(cannelText);
        }

        cannelButton.setOnClickListener(this);
        sureButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        listener.onClick(v);
    }
}
